This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(tidyverse)
Warning: package ‘tidyverse’ was built under R version 4.2.3Warning: package ‘ggplot2’ was built under R version 4.2.3Warning: package ‘tibble’ was built under R version 4.2.3Warning: package ‘tidyr’ was built under R version 4.2.3Warning: package ‘readr’ was built under R version 4.2.3Warning: package ‘purrr’ was built under R version 4.2.3Warning: package ‘dplyr’ was built under R version 4.2.3Warning: package ‘stringr’ was built under R version 4.2.3Warning: package ‘forcats’ was built under R version 4.2.3Warning: package ‘lubridate’ was built under R version 4.2.3── Attaching core tidyverse packages ────────────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.2 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.1 ── Conflicts ──────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(ggplot2)
capacity <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/capacity.csv')
Rows: 49 Columns: 7── Column specification ──────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (1): type
dbl (6): year, standalone_prior, hybrid_prior, standalone_new, hybrid_new, total_gw
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
g <- ggplot(data=capacity %>% filter(type == "Solar")) + geom_line(aes(x=year,y=total_gw))
print(g)
g <- ggplot(data=capacity %>% filter(type == "Solar")) + geom_line(aes(x=year,y=total_gw)) + geom_point(aes(x=year,y=total_gw))
print(g)
g <- ggplot() +
geom_line(data=capacity %>% filter(type=="Solar"),aes(x=year,y=total_gw), color="red") +
geom_line(data=capacity %>% filter(type=="Wind"),aes(x=year,y=total_gw), color="blue")
print(g)
g <- ggplot() %>%
geom_line(data=capacity %>% filter(type=="Solar"),aes(x=year,y=total_gw), color="red") %>%
geom_line(data=capacity %>% filter(type=="Wind"),aes(x=year,y=total_gw), color="blue")
Error in `geom_line()`:
! `mapping` must be created by `aes()`
ℹ Did you use `%>%` or `|>` instead of `+`?
Backtrace:
1. ... %>% ...
4. ggplot2::geom_line(...)
g <- ggplot(data=capacity %>% filter(type %in% c("Solar","Wind","Storage"))) + geom_line(aes(x=year,y=total_gw,color=type))
print(g)
g <- ggplot(data=capacity) + geom_line(aes(x=year,y=total_gw,color=type))
print(g)
g <- ggplot() +
geom_line(data=capacity %>% filter(type == "Solar"), aes(x=year,y=total_gw,color=type)) +
geom_line(data=capacity %>% filter(type == "Wind"), aes(x=year,y=total_gw,color=type)) +
geom_line(data=capacity %>% filter(type == "Storage"),aes(x=year,y=total_gw,color=type))
print(g)
g <-
#Data
ggplot(data=capacity %>% filter(type %in% c("Solar","Wind","Storage"))) +
# Graph and Aesthetics
geom_line(aes(x=year,y=total_gw,color=type),size=1.5) +
# Labels
ylab("Total Gigawatts") + # Y-axis label
xlab("Year") + # X-axis label
labs(color = "Energy Type") + # Legend label (if necessary)
# Scales and limits
scale_x_continuous(breaks = seq(2014,2020, by=1)) + # X axis
scale_y_continuous(limits = c(0,500)) + # Y axis
# Theme
theme_minimal()+
theme(plot.title=element_text(size = 16, face = "bold"), #Title Font and Size
axis.text=element_text(size=12), #Axis Label Font and Size
axis.title=element_text(size=14,face="bold"))+ #Axis Title Font and Size
# Title
ggtitle("Growth of Renewable Energy Sources")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
Please use `linewidth` instead.
print(g)
ggsave("output/growth-little.png",width=1500,height=1500, units = "px")
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
ggplotly(g)